Grokking Scalable Systems for Interviews
Rate this course
Ask Author
Contribute
Back to course home

4% completed

Vote For New Content
Introduction
Course Overview
Who This Course Is for
Caching
What Is Negative Caching and When Should You Cache 404 or Empty Results?
What Is the Difference Between Soft TTL and Hard TTL, and Why Does It Matter?
How Can a Bloom Filter Reduce Cache or Database Load?
What Is Distributed Locking for Cache Rebuilds, and How Does It Prevent Cache Stampedes?
Load Balancing
What Are Sticky Sessions (Session Affinity) and When Should I Avoid Them?
What Is the Difference between Liveness Checks and Readiness Checks in Load Balancers?
What is Global Server Load Balancing (GSLB) and How GeoDNS and Anycast Work?
What are the Main API Pagination Strategies (offset, cursor, keyset), and When Should I Use Each?
What are HTTP Conditional Requests (ETag, If‑None‑Match, Last‑Modified) and How They Reduce Load?
What Is the Difference between Rate Limiting and Throttling and Quotas?
What Are Idempotency Keys and How to Implement Them Safely for Payments
What are SQL Isolation Levels (Read Committed, Repeatable Read, Serializable), and What Anomalies Do They Prevent?
What Is a Write‑Ahead Log (WAL), and How Does It Ensure Durability?
What Is the Difference Between Synchronous and Asynchronous Replication, and When Should I Use Read Replicas?
What Is MVCC (Multi‑Version Concurrency Control), and How Does It Enable Concurrent Reads and Writes?
What Are Safe Patterns for Online Schema Changes vs. Offline Migrations?
What is Little’s Law and How to Use It for Quick Capacity Estimates in System Design
How Can I do Back-of-the-Envelope Sizing for QPS, Bandwidth, Storage, and Peak vs. Average Load?
What are Cold Starts and Warm Starts, and Why Do They Matter for Performance?
How Do I Choose a Good Shard Key and Avoid Hotspots (Bucketing and Key Randomization)?
What Are Range Sharding, Directory‑Based Sharding, and Geo‑Sharding, and What Are the Common Use Cases?
What Is the Difference Between Rendezvous Hashing and Consistent Hashing, and When Should I Use Each?
What Do At‑most‑once, At‑least‑once, And Exactly‑once Delivery Semantics Mean?
What Are Idempotent Producers And Consumers, And How Do De‑duplication Keys Work?
What Is Message Ordering, How Do Partition Keys Affect It, And When Can Ordering Break?
What Are Windowing And Watermarking In Streaming Systems, In Simple Terms?
What Is Quorum (N, R, W), And Why Does R + W > N Give Strongly Consistent Reads?
What Are Common Conflict Resolution Strategies (Last‑write‑wins, Vector Clocks, Logical Clocks)?
What Are Read Repair, Hinted Handoff, And Anti‑entropy (Merkle Trees) In Eventually Consistent Systems?
What Is The Difference Between SLI, SLO, And SLA, And Can You Give Simple Examples?
What Is Opentelemetry, And How Do Traces, Spans, Metrics, And Logs Fit Together?
What Is An Error Budget, And How Should It Guide Release Decisions?
What Are The Trade‑offs Between Server‑stored Sessions And JWTs for Authentication?
What Is The Difference Between TLS And MTLS, And When Is MTLS Appropriate For Service‑to‑service Auth?
What Is Secrets Management, And How Do Environment Variables, KMS, And Vault Compare?
What Is A Replay Attack, And How Is It Different from Idempotency Issues?
What Are The Differences Between TCP, UDP, And QUIC, And When Should I Use Each?
What Is The Difference Between A Forward Proxy, A Reverse Proxy, And NAT?
What Changed From HTTP/1.1 To HTTP/2 To HTTP/3, And What Are Head‑of‑line Blocking And Multiplexing?
What Is the Difference Between Content‑Addressable Storage and Location‑Based Addressing?
What Are Checksums and Etags, and How Do MD5/SHA Compare to CRC for Integrity?
What Are Hot, Warm, Cold, and Archive Storage Tiers, and When Should I Use Each?
What Is the Outbox Pattern, and How Does Change Data Capture (CDC) Work at a High Level?
What Is CQRS (Command Query Responsibility Segregation), and When Should I Consider It?
What Are the Differences Between a Circuit Breaker, Retry With Backoff, and Rate Limiting?
What Are RPO and RTO, and How Do They Differ in Disaster Recovery Planning?
What Is the Difference Between Active‑Active and Active‑Passive Architectures?
What Is Graceful Degradation, and How Do Feature Flags Help Availability?
What Are the Differences Between UUID, ULID, KSUID, and Snowflake IDs, and How Do I Choose?
How Do Snowflake‑Style IDs Work (Timestamp, Worker, Sequence), and What Problems Do They Solve?
What Is the Difference Between Wall‑Clock Time and Monotonic Time, and Why Is Clock Skew Hard?
Final Words
Key Takeaways
What To Learn Next
What Is the Difference between Liveness Checks and Readiness Checks in Load Balancers?

Liveness checks verify that an application instance is still running properly (triggering a restart if it's not), whereas readiness checks determine if the application is prepared to handle requests (controlling whether a load balancer sends traffic to it).

What Is a Liveness Check?

A liveness check (or liveness probe in Kubernetes terminology) is a health check that answers the question: “Should this application instance be kept running, or has it failed?”

In practice, a liveness check is a lightweight test to confirm the process is alive and functioning.

If a liveness check fails, it signals that the application is in a bad state (e.g. crashed or unresponsive), and the orchestrator or environment will restart the instance to recover from that failure.

For example, Kubernetes uses liveness probes to detect situations like deadlocks or crashes – issues where an application cannot recover on its own and restarts the container to restore service availability.

Key points about liveness checks:

  • Purpose: Ensure the application continues to run. It’s essentially a heartbeat or ping; if the heart stops (check fails), the platform assumes the app is dead and needs restarting.

  • Behavior on Failure: A failing liveness check triggers a restart. In Kubernetes, the kubelet will kill and restart the container when the liveness probe fails. In other environments, a monitoring system might trigger a restart or alert an operator.

  • Typical Implementation: Liveness checks are often minimal and fast. For instance, an HTTP liveness endpoint might just return an “OK” (200 status) if the app’s main loop is running. It doesn’t usually perform heavy dependency checks. It’s simply confirming the app isn’t hung or crashed.

  • Examples: A simple liveness probe could be an HTTP GET to /health that returns success if the app process is up. Alternatively, it could be a low-level check (like responding to a ping or executing a trivial command in the app). If this check fails (e.g., the app doesn’t respond or returns an error), the system knows the app isn’t healthy and should be restarted.

What Is a Readiness Check?

A readiness check (a.k.a. readiness probe) is a health check that answers a different question: “Is this application instance ready to serve incoming requests right now?”

Even if the application is running (alive), it might not be ready to handle traffic.

Readiness checks are designed to prevent traffic from reaching instances that can’t fully serve requests.

When a readiness check fails, the instance is marked unready and removed from the load balancer’s pool of active servers.

Unlike liveness, a failing readiness check does not restart the app. It simply tells the load balancer (or orchestrator) to stop sending new traffic to that instance until it becomes ready again.

Key points about readiness checks:

  • Purpose: Ensure the application can accept and properly handle traffic. It guards the entry point, so clients only send requests to instances that are fully operational (preventing errors or timeouts to users).

  • Behavior on Failure: A failing readiness check removes the instance from service. The load balancer will stop routing requests to that server/pod until the readiness check passes again. The application keeps running in the background, potentially recovering or completing its startup tasks.

  • Typical Implementation: Readiness checks often involve verifying external dependencies or specific application state. For example, a readiness endpoint might check that the app has connected to its database, loaded necessary data, or completed initialization. Because of this, readiness probes can be a bit more in-depth (and sometimes slower) than liveness probes. They are often implemented as an HTTP endpoint (e.g. /ready or /healthz) that returns success only if all required components are working (database connections, caches, third-party services, etc.).

  • Examples: Suppose an application needs to load a large configuration or warm up caches at startup. It might report “not ready” during this warm-up. A readiness check endpoint could return an error or unfavorable status until the warm-up is complete, ensuring the load balancer does not send users to it prematurely. Once the setup is done, the endpoint returns success, and the instance is marked ready to receive traffic. Similarly, if an application loses connection to a critical dependency (like a database), it could dynamically fail its readiness check, signaling the load balancer to temporarily stop sending new requests until the issue is resolved.

Liveness vs Readiness: Key Differences

Both liveness and readiness checks are types of health checks used in modern cloud environments (especially in microservices and container orchestration like Kubernetes) to improve reliability. However, they serve different roles.

Liveness Checks vs. Readiness Checks
Liveness Checks vs. Readiness Checks

Here’s a side-by-side comparison:

  • Primary Question: Liveness asks “Is the app alive (and not stuck)?”, while Readiness asks “Is the app ready to serve?”.

  • Action on Failure: Liveness failures restart the application instance (think of it as self-healing a broken app). Readiness failures pull the instance out of traffic rotation without killing it. The instance can continue running and recover, but it won’t get requests until it reports ready.

  • Impact on Load Balancing: If a liveness check fails, the instance is usually already effectively “down” (it may be restarted and eventually removed from the pool due to being offline during restart). If a readiness check fails, the load balancer proactively stops sending traffic to that instance, even though it’s still running, to prevent bad user requests. In Kubernetes, a Pod failing readiness is removed from Service endpoints (so no traffic from the Service reaches it).

  • Scope of Check: Liveness checks are typically narrow: they might only verify the application process is running (e.g., thread alive or basic HTTP 200 response). Readiness checks are often broader: they may verify that all required resources are in place for the app to do its job (e.g., database connection alive, dependent services reachable, data loaded).

  • When They’re Used: Readiness checks are crucial during startup and deployment cycles. For instance, during a rolling deployment or autoscaling event, new instances will only receive traffic when their readiness checks pass, ensuring zero-downtime deployments. Liveness checks run continuously (or periodically) to catch unexpected failures at any time (e.g., a memory leak causing a hang after hours of uptime).

  • Outcome if Misused: If you rely only on readiness checks and never implement liveness, a crashed or hung service might stay down indefinitely without automated restart – the load balancer will stop sending traffic, but you’d have one less instance until someone intervenes. Conversely, if you rely only on liveness checks, the system might restart instances for issues that could have been transient; during restarts, users might get errors. Using both ensures that transient issues (like a brief dependency outage) don’t trigger full restarts (readiness handles it), while truly stuck services do get restarted (liveness handles that). It’s generally recommended to use both in tandem for robust health management.

Why Are These Checks Important in Load Balancing?

In load-balanced architectures, liveness and readiness checks are vital for high availability and smooth deployments:

  • High Availability: Load balancers distribute traffic across multiple servers or containers. Readiness checks help the load balancer send traffic only to healthy, ready instances, so users don’t hit a server that will reject or drop requests. Liveness checks ensure that if an instance does crash or freeze, it gets replaced or rebooted automatically, maintaining the overall health of the service cluster.

  • Zero-Downtime Deployments: When deploying updates (rolling updates), readiness probes allow new instances to come online, initialize, then signal “ready” before they start receiving traffic. At the same time, older instances can be drained (marked not ready) so they stop receiving new traffic and can shut down gracefully. This coordination via readiness checks ensures continuous service to users without downtime.

  • Graceful Degradation: If an application instance encounters a temporary issue (e.g., cannot reach a dependency or is overloaded), failing its readiness check will pull it out of rotation. The rest of the system can continue serving requests with the remaining healthy instances, and the troubled instance can recover without impacting user traffic. From a site reliability engineering (SRE) perspective, this is a form of graceful degradation. The system automatically adjusts to serve only from healthy components.

  • Auto-Healing: Liveness checks provide an auto-healing mechanism. For example, consider an app that deadlocks (threads freeze); it won’t respond to requests, but it hasn’t outright crashed. A liveness probe can detect this (the app fails to respond to the liveness endpoint or heartbeat) and trigger a restart, recovering service automatically. Without liveness checks, such hung processes might continue to sit unresponsive indefinitely, causing part of your application pool to be effectively dead.

  • Protection Against False Alarms: By separating readiness and liveness, you avoid needless restarts. For instance, if a database goes down for a minute, a readiness check can fail (so the instance stops taking traffic) but the liveness check can still pass (the app process is alive). This way, the app isn’t restarted by the orchestrator for an external issue; once the database comes back, the app can resume serving traffic immediately. If you only had a liveness check tied to a database call, the app might be killed and restarted unnecessarily.

What Are Sticky Sessions (Session Affinity) and When Should I Avoid Them?
What is Global Server Load Balancing (GSLB) and How GeoDNS and Anycast Work?
Mark as Completed

On this page

What Is a Liveness Check?

What Is a Readiness Check?

Liveness vs Readiness: Key Differences

Why Are These Checks Important in Load Balancing?